<?php 
class App_Model_Entity 
{   
    protected  $_mapper;
    
	public function __construct($data = null)
	{
	    if($data !== null){
		    if(is_array($data)){
				foreach($this->_data as $key => $value)
				{
					$this->_data[$key] = $data[$key];
				}
		    } else {
		    	throw new Exception('Data must be array');
		    }
	    }
	}
	
    public function __get($value)
    {
        if(array_key_exists($value, $this->_data)){
            return $this->_data[$value];
        }
    } 
    
    public function __set($field, $value)
    {
    	if(array_key_exists($field, $this->_data)){
           $this->_data[$field] = $value;
        } else {
            throw new Exception('Field not found');
        }
    }
    
    public function __isset($field)
    {
        return isset($this->_data[$field]);
    }
    
    public function __unset($field)
    {
        if(isset($this->_data[$field])){
            unset($this->_data[$field]);
        }
    }
    
    public function toArray()
    {
        return $this->_data;
    }
    
    public function setMapper($mapper)
    {
    	$this->_mapper = $mapper;
    }
    
    public function getMapper()
    {
    	return $this->_mapper;
    }
}